package com.hss.nestscroll;

import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AppCompatActivity;
import android.transition.Explode;
import android.transition.Slide;
import android.transition.Transition;
import android.transition.TransitionInflater;
import android.transition.Visibility;
import android.view.Gravity;

import com.hss.recyclerviewtest.R;

public class NestScrollActivity extends AppCompatActivity {
    int type = 0;
    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_button_ripple);
//        setupWindowAnimations();
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    private void setupWindowAnimations() {
        Transition transition = null;

        switch (type) {
            case 0:
                transition = buildEnterTransitionByCode();
                break;
            case 1:
                transition = buildEnterTransitionByXml();
                break;
            default:
                break;
        }
        getWindow().setEnterTransition(transition);
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    private Transition buildEnterTransitionByCode() {
        Slide enterTransition = new Slide();
        enterTransition.setDuration(500);
        enterTransition.setSlideEdge(Gravity.RIGHT);
        return enterTransition;

//        Explode enterTransition = new Explode();
//        enterTransition.setDuration(500);
//        return enterTransition;
    }

    @RequiresApi(api = Build.VERSION_CODES.KITKAT)
    private Transition buildEnterTransitionByXml() {
        return TransitionInflater.from(this).inflateTransition(R.transition.slide_from_bottom);
    }


    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    @Override
    public void onBackPressed() {

        Visibility returnTransition = buildReturnTransition();
        getWindow().setReturnTransition(returnTransition);
//        finishAfterTransition();
        supportFinishAfterTransition();
//        super.onBackPressed();
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    private Visibility buildReturnTransition() {
        Visibility enterTransition = new Slide();
        enterTransition.setDuration(500);
        return enterTransition;
    }
}
